package numberFour;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class NumberFour {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        Class<Person> personClass = Person.class;
        Constructor<Person> constructor = personClass.getConstructor();
        Person niuma = constructor.newInstance();
        Method setName = personClass.getDeclaredMethod("setName",String.class);
        setName.invoke(niuma,"牛马");
        Field age = personClass.getDeclaredField("age");
        age.setAccessible(true);
        age.set(niuma,21);
        System.out.println(niuma);
    }
}
